import React, { PureComponent } from 'react'

import { connect } from '../utils/connect'
import { addAction } from '../store/actionCreators'

class Home extends PureComponent {
  
  render() {
    return (
      <div>
        <h1>Home</h1>
        <h2>当前计数：{this.props.counter}</h2>
        <button onClick={e => this.props.increment()}>+1</button>
        <button onClick={e => this.props.addNumber(6)}>+6</button>
      </div>
    )
  }
}

const mapStateToProps = state => {
  return {
    counter: state.counter
  }
};
const mapDispachToProp = dispatch => {
  return {
    increment: function () {
      dispatch(addAction(1))
    },
    addNumber: function (num) {
      dispatch(addAction(num))
    }
  }
};;

export default connect(mapStateToProps,mapDispachToProp)(Home)
